package org.example.primitive;

/**
 * cd base/target/classes
 * javap -c org/example/primitive/IntegerDemo.class
 */
public class IntegerDemo {

    public static void main(String[] args) {
        IntegerDemo integerDemo=new IntegerDemo();
        integerDemo.integerCache();
        integerDemo.boxAndUnbox();
    }

    public void boxAndUnbox() {
        Integer int1=2;//装箱
        int int2=int1;//拆箱
        System.out.println(int1==int2);//true 拆箱后比较
    }

    public void integerCache() {
        Integer int1=2;
        Integer int2=2;

        Integer int3=Integer.valueOf(2);
        Integer int4=Integer.valueOf(2);

        Integer int5=Integer.valueOf(128);
        Integer int6=Integer.valueOf(128);

        System.out.println(int1==int2);//true
        System.out.println(int1==int3);//true
        System.out.println(int3==int4);//true
        System.out.println(int5==int6);//false
    }
}
